//
//  MateSetUpPopView.m
//  TQY
//
//  Created by 甘世清 on 2024/10/2.
//

#import "MateSetUpPopView.h"
#import <BRPickerView/BRPickerView.h>
#import "SQLocationPopView.h"
@implementation MateSetUpPopView

- (void)SQ_UIViewForSelfView{
    self.backgroundColor = SQColorF5F5F5;
    self.layer.cornerRadius = 30;
    
    UILabel * label = [[UILabel alloc]init];
    label.text = SQNSLocalString(@"筛选条件");
    label.textColor = SQColor333333;
    label.font = FONT_MEDIUM(16);
    [self addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(self).offset(24);
    }];
    
    [self addSubview:self.typeView];
    [self addSubview:self.cityView];
    [self addSubview:self.genderView];
    [self.typeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self).offset(60);
        make.height.mas_equalTo(76);
    }];
    
    [self.cityView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.typeView.mas_bottom).offset(14);
        make.height.mas_equalTo(76);
    }];
    
    [self.genderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.cityView.mas_bottom).offset(14);
        make.height.mas_equalTo(76);
    }];
    [self addSubview:self.yesBtn];
    [self.yesBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.mas_equalTo(SCREEN_WIDETH-40);
        make.bottom.equalTo(self.mas_bottom).offset(-FootHeight-30);
        make.height.mas_equalTo(50);
    }];
    [self SQ_Header];
}

- (void)SQ_Header{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:@"lug_type" forKey:@"key"];
    [HttpTool post:@"config/details" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        NSDictionary * data = [[NSDictionary alloc]initWithDictionary:httpModel.data];
        NSString * value = [NSString stringWithFormat:@"%@",[data objectForKey:@"value"]];
        NSArray * array = [value mj_JSONObject];
        [self.jsonArray removeAllObjects];
        [self.jsonArray addObjectsFromArray:array];
        [self.jsonArray insertObject:@"全部" atIndex:0];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
}
-(void)SQ_buttonclicktype{
    /// 单列文本选择器
    WS(weakSelf);
    BRStringPickerView *textPickerView = [[BRStringPickerView alloc]initWithPickerMode:BRStringPickerComponentSingle];
    textPickerView.pickerStyle = [self SQ_getStyle];
    textPickerView.title = @"活动类型";
    // 设置数据源
    textPickerView.dataSourceArr = self.jsonArray;
    textPickerView.selectIndex = [textPickerView.dataSourceArr indexOfObject:self.typeView.rightLabel.text];
    [textPickerView setResultModelBlock:^(BRResultModel * _Nullable resultModel) {
        weakSelf.typeView.rightName = resultModel.value;
        if ([resultModel.value  isEqualToString:@"全部"]) {
            
        } else {
            [weakSelf.seletedDic setObject:resultModel.value forKey:@"category"];
        }
    }];
    [textPickerView show];
}
-(void)SQ_buttonclickcity{
    if (![[UserModel share].city isNotEmpty]) {
        [self SQ_HeaderViewqButtonClick];
        return;
    } 
    /// 单列文本选择器
    WS(weakSelf);
    BRStringPickerView *textPickerView = [[BRStringPickerView alloc]initWithPickerMode:BRStringPickerComponentSingle];
    textPickerView.pickerStyle = [self SQ_getStyle];
    textPickerView.title = @"活动所在地区";
    // 设置数据源
    textPickerView.dataSourceArr = @[@"全部", @"同城"];
    textPickerView.selectIndex = [textPickerView.dataSourceArr indexOfObject:self.cityView.rightLabel.text];
    [textPickerView setResultModelBlock:^(BRResultModel * _Nullable resultModel) {
        weakSelf.cityView.rightName = resultModel.value;
        if ([resultModel.value  isEqualToString:@"全部"]) {
            
        } else {
            [weakSelf.seletedDic setObject:[UserModel share].city forKey:@"address"];
        }
    }];
    [textPickerView show];
}

-(void)SQ_HeaderViewqButtonClick{
    WS(weakSelf);
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:SQNSLocalString(@"设置定位权限") message:@"该功能需要访问您当前定位进行匹配,请开启定位后使用" preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction * co1 = [UIAlertAction actionWithTitle:SQNSLocalString(@"去开启") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        if ([[UIApplication sharedApplication] canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
            }];
        }
    }];
    UIAlertAction * co2 = [UIAlertAction actionWithTitle:SQNSLocalString(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:co1];
    [alert addAction:co2];
    [[Manager SQ_getCurrentViewController] presentViewController:alert animated:YES completion:nil];
}

-(void)SQ_buttonclickgender{
    /// 单列文本选择器
    WS(weakSelf);
    BRStringPickerView *textPickerView = [[BRStringPickerView alloc]initWithPickerMode:BRStringPickerComponentSingle];
    textPickerView.pickerStyle = [self SQ_getStyle];
    textPickerView.title = @"发布者的性别";
    // 设置数据源
    textPickerView.dataSourceArr = @[@"全部", @"男性", @"女性"];
    textPickerView.selectIndex = [textPickerView.dataSourceArr indexOfObject:self.genderView.rightLabel.text];
    [textPickerView setResultModelBlock:^(BRResultModel * _Nullable resultModel) {
        weakSelf.genderView.rightName = resultModel.value;
        if ([resultModel.value  isEqualToString:@"全部"]) {
            
        } else {
            [weakSelf.seletedDic setObject:@(resultModel.index) forKey:@"gender"];
        }
    }];
    [textPickerView show];
}
- (SQCustomButton *)yesBtn{
    if (!_yesBtn) {
        _yesBtn = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(0, 0) midmargin:0];
        _yesBtn.text = SQNSLocalString(@"确定");
        _yesBtn.textColor = UIColor.whiteColor;
        _yesBtn.font = FONT_MEDIUM(16);
        _yesBtn.backgroundColor = SQColor3DA59D;
        _yesBtn.layer.cornerRadius = 25;
        _yesBtn.layer.masksToBounds = YES;
    }
    return _yesBtn;
}

- (IssueTypeView *)cityView{
    if (!_cityView) {
        _cityView = [[IssueTypeView alloc]init];
        _cityView.name = SQNSLocalString(@"地区");
        _cityView.rightName = SQNSLocalString(@"全部");
        [_cityView.btn addTarget:self action:@selector(SQ_buttonclickcity) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cityView;
}

- (IssueTypeView *)typeView{
    if (!_typeView) {
        _typeView = [[IssueTypeView alloc]init];
        _typeView.name = SQNSLocalString(@"类型");
        _typeView.rightName = SQNSLocalString(@"全部");
        [_typeView.btn addTarget:self action:@selector(SQ_buttonclicktype) forControlEvents:UIControlEventTouchUpInside];
    }
    return _typeView;
}

- (IssueTypeView *)genderView{
    if (!_genderView) {
        _genderView = [[IssueTypeView alloc]init];
        _genderView.name = SQNSLocalString(@"性别");
        _genderView.rightName = SQNSLocalString(@"全部");
        [_genderView.btn addTarget:self action:@selector(SQ_buttonclickgender) forControlEvents:UIControlEventTouchUpInside];
    }
    return _genderView;
}

-(BRPickerStyle*)SQ_getStyle{
    BRPickerStyle * style = [BRPickerStyle new];
    style.alertViewColor = UIColor.whiteColor;
    style.pickerColor = UIColor.whiteColor;
    style.titleBarColor= UIColor.whiteColor;
    style.hiddenTitleLine = YES;
    style.titleTextColor = SQColor333333;
    style.cancelTextColor = SQColor333333;
    style.doneTextColor = SQColor333333;
    style.rowHeight = 50;
    style.pickerTextColor = SQColor333333;
    style.separatorColor = SQColor3DA59D;
    return style;
}
- (NSMutableArray *)jsonArray{
    if (!_jsonArray) {
        _jsonArray = [[NSMutableArray alloc]init];
    }
    return _jsonArray;
}
- (NSMutableDictionary *)seletedDic{
    if (!_seletedDic) {
        _seletedDic = [[NSMutableDictionary alloc]init];
    }
    return _seletedDic;
}
@end
